var api, W;
var initForm = function(){
	$('#_form_default').form({
		url :'sys/SysAccessoryExt/upload',
		onBeforeLoad : function(param){
			$.messager.progress();
		},
		onLoadSuccess : function(data) {
			//加载完成之后才构建
			$.messager.progress("close");
			if(_is_not_empty(data.ownerType) && data.ownerType == 'HT'){
				$('#accessoryClass').mSelect({
					myClass:'easyui-validatebox',
					baseCode:'Accessory_Class_Contract_Code',
					isAllSelect:false,
					dataOptions:'required:true'
				});
				$('#accessoryClass').val(data.accessoryClass);
			}
		},
		onLoadError : function(data) {
			//加载完成之后才构建
			$.messager.progress("close");
			$.messager.alert('提示', "加载内容失败,请重新刷新页面/联系管理员", "error");
		},
		onSubmit : function(param) {
			if (!$(this).form("validate")) {
				$.messager.alert('提示', "提交的选项中,有错误内容,请检查", "error");
				return false;
			}
			$.messager.progress();
		},
		success : function(data) {	
			$.messager.progress("close");
			var jd = eval('(' + data + ')');
			if(!!!jd){
				$.messager.alert('提示', "未知异常", "error");
				return false;
			}
			if(jd.state!=200){
				$.messager.alert('提示', jd.message, "error");
				return false;
			}
			$.dialog.alert('操作成功!',function(){
				api.close();
			});
		}
	});
};

$(function(){
	initForm();
	api = frameElement.api;W = api.opener;
	$('#accessoryClass').mSelect({
		myClass:'easyui-validatebox',
		baseCode:'Accessory_Class_Apply_Code',
		isAllSelect:false,
		dataOptions:'required:true'
	});
	
	$('#ownerType').mSelect({
		myClass:'easyui-validatebox',
		baseCode:'Accessory_Loan_ownerType_Code',
		isAllSelect:false,
		dataOptions:'required:true',
		onchageCallback:function(text,value){
            if(value == 'HT'){
          	  $('#accessoryClass').mSelect({
          			myClass:'scselect',
          			width:192,
          			baseCode:'Accessory_Class_Contract_Code',
          			isAllSelect:true
          		});
            }else{
          	  $('#accessoryClass').mSelect({
          			myClass:'scselect',
          			width:192,
          			baseCode:'Accessory_Class_Apply_Code',
          			isAllSelect:true
          			
          		});
            }
		}
	});
	
	if(typeof(_param_id)!='undefined' && _param_id.length > 0){
		$("#_form_default").form('load','sys/SysAccessory/findByPk?pks=' + _param_id);
	}
	$('input[name="confirm_button"]').click(function(){
		$('#_form_default').submit();
	});
	
});
